<template>
  <div class="project">
    <!-- 头部 -->
  <head-usual :title="title" :to="to"></head-usual>
  <div class="fix-classify">
      <!-- 排序筛选-->
    <div class="body-all">
    <!-- 类型分类 -->
    <div class="body">
        <div class="area nav" @click="switchFilter('status')">
            <span>项目状态</span>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-shang-copy-copy"></use>
            </svg>
        </div>
        <mt-popup class="tlm-popup tlm-popup-1" v-model="showStatus" position="top" popup-transition="popup-fade">
            <ul class="body-tanchu">
                <li class="area-li">
                    <a @click="handleFilter('status',0)" v-bind:class="{ active: 0==searchCondition.status }">不限</a>
                </li>
                <li v-for="(item,index) in this.$store.state.filter_ProStatu" :key="index" >
                    <a @click="handleFilter('status',item.id)" v-bind:class="{ active: item.id==searchCondition.status }">{{item.name}}</a>
                </li>
            </ul>
        </mt-popup>
        <div class="major nav" @click="switchFilter('industrycla')">
            <span>行业分类</span>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-shang-copy-copy"></use>
            </svg>
        </div>
        <mt-popup class="tlm-popup tlm-popup-2" v-model="showIndustrycla" position="top" popup-transition="popup-fade">
            <ul class="body-tanchu">
                <li class="area-li" >
                    <a @click="handleFilter('industrycla',0)" v-bind:class="{ active: 0==searchCondition.industrycla }">不限</a>
                </li>
                <li v-for="(item,index) in this.$store.state.filter_Hyfl" :key="index" >
                    <a @click="handleFilter('industrycla',item.id)" v-bind:class="{ active: item.id==searchCondition.industrycla }">{{item.name}}</a>
                </li>
            </ul>
        </mt-popup>
        <div class="major-classify nav" @click="switchFilter('role')">
            <span>项目角色</span>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-shang-copy-copy"></use>
            </svg>
        </div>
        <mt-popup class="tlm-popup tlm-popup-3" v-model="showRole" position="top" popup-transition="popup-fade" >
            <ul class="body-tanchu">
               <li class="area-li" >
                    <a @click="handleFilter('role','all')" v-bind:class="{ active: 'all'==searchCondition.role }">不限</a>
                </li>
                <li v-for="(item,index) in this.$store.state.filter_Role" :key="index" >
                    <a @click="handleFilter('role',item.name)" v-bind:class="{ active: item.name==searchCondition.role }">{{item.name}}</a>
                </li>
            </ul>
        </mt-popup>
    </div>
    </div>
  <!-- 分类 -->
  <div class="classify">
      <div v-bind:class="(searchCondition.sort.indexOf('t') != -1?'active ':'')+' classify-item'" @click="handleRank('t')">发布时间  {{searchCondition.sort=="t1"?'↓':'↑'}}</div>
      <div v-bind:class="(searchCondition.sort.indexOf('b') != -1?'active ':'')+' classify-item'" @click="handleRank('b')">报名人数 {{searchCondition.sort=="b1"?'↓':'↑'}}</div>
      <div v-bind:class="(searchCondition.sort.indexOf('p') != -1?'active ':'')+' classify-item'" @click="handleRank('p')">价格 {{searchCondition.sort=="p1"?'↓':'↑'}}</div>
  </div>


  </div>
  
   <!-- 项目列表 -->
  <div class="project-list" v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="20" >
      <!-- 每一个收藏的项目 -->
      <div class="project-item" v-for="(item,index) in pagedListData" :key="index">
      <router-link  :to="'/projects/detail/' + item.id" >
          <p class="project-item-1">
              <span class="item1-left">{{item.name}}</span>
              <span class="item1-right" v-if="item.status=='招募中'">{{item.status}}</span>
              <span class="item1-right doing" v-if="item.status=='进行中'">{{item.status}}</span>
              <span class="item1-right done" v-if="item.status=='已完成'">{{item.status}}</span>
              <span class="item1-right doing" v-if="item.status=='竞标中'">{{item.status}}</span>
          </p>
          <div class="project-item-2">
            <p class="project-item-type item">
              <svg class="icon price-bottom-01" aria-hidden="true">
                  <use xlink:href="#icon-leixing"></use>
              </svg>
              <span class="type-special">类型：</span>
              <span>{{item.type}}</span>
            </p>
            <p class="project-item-price item">
              <span class="price-left" v-if="item.isbargaining">可议价</span>
              <span class="price-right">￥{{item.price}} 万</span>
            </p>
          </div>
          <div class="project-item-2">
            <p class="project-item-time item">
                <svg class="icon price-bottom-01" aria-hidden="true">
                    <use xlink:href="#icon-zhouqifuwushiduan"></use>
                </svg>
                <span class="type-special">周期：</span>
                <span>{{item.duration}}</span>
            </p>
          </div>
          <div class="project-item-3">
            <p class="item3-left">
                <span>{{item.hits}} 点击</span>
                <span class="fenge"></span>
                <span>{{item.signUpNum}}人报名</span>
            </p>
            <p  class="item3-right">
                <span>{{item.addtime}}</span>
                <span>发布</span>
            </p>
          </div>
      </router-link>
      </div>
    <div v-show="loading" class="page-infinite-loading">
      <mt-spinner type="fading-circle"></mt-spinner>
      加载中...
    </div>
    <div v-show="allLoaded" class="page-infinite-data">亲！别拉了我是有底线的</div>
  </div>     
  <!-- 底部 -->
  <footerTotal></footerTotal>
  </div>
</template>
<script>
import { GetPagedList } from "@/api/projects";
export default {
  data() {
    return {
      title: "项目列表",
      to:'/',
      pagedListData: [],
      showStatus: false,
      showIndustrycla: false,
      showRole: false,

      searchCondition: {
        area: "", //地区
        status: 0, //状态
        industrycla: 0, //行业分类
        role: "all", //角色
        pageindex: 1, //页码
        sort: "t1" //排序
      },
      loading: false, //是否显示加载中
      allLoaded: false, //加载完毕
      totalpage: 0 //总页码
    };
  },
  created() {
    this._getPagedList();
  },
  methods: {
    //操作排序
    handleRank(cmd) {
      if (this.searchCondition.sort.indexOf("1") != -1) {
        this.searchCondition.sort = cmd + "2";
      } else {
        this.searchCondition.sort = cmd + "1";
      }
      this._getPagedList();
    },
    switchFilter(type) {
      //顶部切换 筛选条件
      switch (type) {
        case "status":
          {
            this.showStatus = true;
            this.showIndustrycla = false;
            this.showRole = false;
          }
          break;
        case "industrycla":
          {
            this.showStatus = false;
            this.showIndustrycla = true;
            this.showRole = false;
          }
          break;
        case "role":
          {
            this.showStatus = false;
            this.showIndustrycla = false;
            this.showRole = true;
          }
          break;
        default:
          break;
      }
    },
    handleFilter(type, value) {
      switch (type) {
        case "status":
          {
            this.searchCondition.status = value;
          }
          break;
        case "industrycla":
          {
            this.searchCondition.industrycla = value;
          }
          break;
        case "role":
          {
            this.searchCondition.role = value;
          }
          break;
        default:
          break;
      }

      this.showStatus = false;
      this.showIndustrycla = false;
      this.showRole = false;
      this._getPagedList();
    },
    loadMore() {
      //分页加载更多
      if (this.searchCondition.pageindex >= this.totalpage) {
        this.allLoaded = true;
        return;
      }
      this.loading = true;
      setTimeout(() => {
        this.searchCondition.pageindex++;
        GetPagedList(this.searchCondition).then(res => {
          if (res.StatusCode === 200) {
            this.pagedListData = this.pagedListData.concat(res.Data);
          }
        });
        this.loading = false;
      }, 1000);
    },
    // 获取数据
    _getPagedList() {
      this.$indicator.open();
      GetPagedList(this.searchCondition).then(res => {
        if (res.StatusCode === 200) {
          this.pagedListData = res.Data;
          this.totalpage = res.TotalPage;
          this.$indicator.close();
        }
      });
    }
  },
};
</script>

<style lang="scss" scoped>
.fix-classify{
  position: fixed;
  left: 0;
  right:0;
  top:52px;
  background: #fff;
  display: block;
  z-index: 999;
}
.body-all {
  position: relative;
}
/* 分类*/
.body {
  width: 100%;
  height: 44px;
  display: flex;
  border-top: 1px solid #f4f4f4;
  text-align: center;
  //分类下每一个选项
  .nav {
    width: 33.3%;
    border-right: 1px solid #f4f4f4;
    // border-bottom: 1px solid #ccc;
    line-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    span {
      font-size: 14px;
      color: #333333;
    }
    .icon{
      font-size: 18px;
    }
    .icon-active {
      color: #fd4f00;
    }
  }
  // 角色分类右边框消失
  .major-classify {
    border-right: none !important;
  }
}
.body-tanchu {
  width: 100%;
  background: white;
  padding: 15px 12px 2px 12px;
  display: flex;
  flex-wrap: wrap;
}
.body-tanchu > li {
  display: flex;
  text-align: center;
  flex:0 0 33.3%;
  margin-bottom: 10px;
  justify-content: center;
  
    a{
       width: 115px;
      height: 34px;
      line-height: 34px;
      border: 1px solid #eeeeee;

    }
  
}
.popup-layer {
  width: 414px;
  background-color: #fff;
  padding: 0;
  margin: 0;
  left: 50%;
  position: absolute;
}
// 弹出阴影层
.body-all > .v-modal {
  width: 100%;
  height: 73%;
}
.hidden {
  width: 100%;
  z-index: 99999;
  height: 88px;
  position: absolute;
  top: -44px;
  left: 0;
  background-color: white;
  opacity: 0;
}
.active {
  border-color: #fd4f00 !important;
  color: #fd4f00 !important;
}
/* 3个排序 */
.classify {
  width: 100%;
  height: 42px;
  background: #f9f9f9;
  display: flex;
  align-items: center;
  text-align: center;
  border-bottom: 1px solid #eeeeee;
  .classify-item {
    width: 33.3%;
    font-size: 14px;
    color: #282828;
  }
  .active {
    color: #fd4f00 !important;
  }
}
.project-list{
  margin-top: 85px;
}
// 每一个收藏的项目
.project-item {
  overflow: hidden;
  border-bottom: 10px solid #f4f4f4;
  // 第一行
  .project-item-1 {
    font-size: 16px;
    color: #282828;
    padding: 0 12px;
    overflow: hidden;
    margin-bottom: 18px;
    margin-top: 21px;
    .item1-left {
      display: block;
      float: left;
    }
    .item1-right {
      display: block;
      float: right;
      color: #ffffff;
      font-size: 12px;
      padding: 0px 8px;
      background: #3887fe;
      border-radius: 9px;
      margin-top: 2.5px;
    }
    .doing {
      background: #fd4f00;
    }
    .done {
      background: #999999;
    }
  }
  //第二行
  .project-item-2 {
    display: flex;
    justify-content: space-between;
    padding: 0 12px;
    align-items: center;
    margin-bottom: 10px;
    font-size: 14px;
    .item {
      text-align: center;
      display: flex;
      align-items: center;
    }
    .project-item-type {
      span {
        color: #666666;
      }
      .type-special {
        color: #999999;
      }
      .icon {
        display: block;
        margin-right: 5px;
        color: #999999;
      }
    }
    .project-item-time {
      span {
        display: block;
        float: left;
        color: #666666;
      }
      .type-special {
        color: #999999;
      }
      .icon {
        display: block;
        margin-right: 5px;
        color: #999999;
        font-size: 16px;
        margin-left:-2px;
      }
    }
    .project-item-price {
      .price-left {
        color: #999999;
        // padding-left: 12px;
      }
      .price-right {
        color: #fd4f00;
        font-size: 16px;
        display: block;
        float: left;
      }
    }
  }
  //  第三行
  .project-item-3 {
    overflow: hidden;
    margin-left: 12px;
    margin-right: 12px;
    margin-top: 12px;
    color: #999999;
    margin-bottom: 21px;
    font-size: 14px;
    .item3-left {
      float: left;
      display: flex;
      align-items: center;
      span {
        float: left;
        display: block;
      }
      .fenge {
        width: 1px;
        height: 11px;
        border: 1px solid #999999;
        display: block;
        float: left;
        margin-left: 9px;
        margin-right: 9px;
      }
    }
    .item3-right {
      float: right;
    }
  }
}
</style>
